include(AddFlagUtils)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compiler_flag(OPTIONAL "WNO_EXIT_TIME_DESTRUCTORS" "-Wno-exit-time-destructors")
  add_compiler_flag(OPTIONAL "WNO_GLOBAL_CONSTRUCTORS" "-Wno-global-constructors")
  add_compiler_flag(OPTIONAL "WNO_DISABLED_MACRO_EXPANSION" "-Wno-disabled-macro-expansion")
  add_compiler_flag(OPTIONAL "WNO_USED_BUT_MARKED_UNUSED" "-Wno-used-but-marked-unused")
endif()

function(add_unit_test)
  string(REPLACE ";" "-" test_name "${ARGV}")
  string(REPLACE ";" "/" test_path "${ARGV}")
  set(test_build_target "test-core-${test_name}")
  add_executable(${test_build_target} "${test_path}.cpp")
  target_link_libraries(${test_build_target}
    ${GMPXX_LIB}
    ${GMP_LIB}
    ${Boost_LIBRARIES})
  if (APRON_FOUND)
    target_link_libraries(${test_build_target} ${APRON_LIBRARIES})
  endif()
  add_dependencies(build-core-tests ${test_build_target})

  add_test(NAME "core-${test_name}" COMMAND ${test_build_target})
endfunction()

add_unit_test(adt patricia_tree map)
add_unit_test(adt patricia_tree set)
add_unit_test(number z_number)
add_unit_test(number q_number)
add_unit_test(number machine_int)
add_unit_test(value numeric constant)
add_unit_test(value numeric interval)
add_unit_test(value numeric congruence)
add_unit_test(value numeric gauge)
add_unit_test(value machine_int interval)
add_unit_test(value machine_int constant)
add_unit_test(value machine_int congruence)
add_unit_test(value machine_int interval_congruence)
add_unit_test(domain discrete_domain)
add_unit_test(domain numeric constant)
add_unit_test(domain numeric interval)
add_unit_test(domain numeric congruence)
add_unit_test(domain numeric interval_congruence)
add_unit_test(domain numeric dbm)
add_unit_test(domain numeric octagon)
add_unit_test(domain numeric gauge)
add_unit_test(domain numeric gauge_interval_congruence)
add_unit_test(domain numeric union)
add_unit_test(domain numeric var_packing_domain)
add_unit_test(domain numeric var_packing_dbm)
add_unit_test(domain numeric var_packing_dbm_congruence)
if (APRON_FOUND)
  add_unit_test(domain numeric apron interval)
  add_unit_test(domain numeric apron polka_polyhedra)
  add_unit_test(domain numeric apron ppl_linear_congruences)
  add_unit_test(domain numeric apron pkgrid_polyhedra_lin_congruences)
endif()
add_unit_test(domain machine_int interval)
add_unit_test(domain machine_int congruence)
add_unit_test(domain machine_int interval_congruence)
add_unit_test(domain machine_int numeric_domain_adapter)
add_unit_test(domain machine_int polymorphic_domain)
add_unit_test(domain pointer solver)
add_unit_test(domain nullity separate_domain)
add_unit_test(domain uninitialized separate_domain)
add_unit_test(domain memory partitioning)
add_unit_test(example muzq)
add_unit_test(fixpoint wpo)
